import React, {Component} from 'react';
import './News_list.css';
import {Table,Button, Modal, Input} from "antd";

const iniData = [{
            "name": '北京水泥厂',
            "location": '北京市',
            "title": '2015信息简表',
            "author": 'czh'
        },{
            "name": '武汉水泥厂',
            "location": '武汉市',
            "title": '2015信息简表',
            "author": 'czh'
        },{
            "name": '南京水泥厂',
            "location": '南京市',
            "title": '2015信息简表',
            "author": 'czh'
        },{
            "name": '重庆水泥厂',
            "location": '重庆市',
            "title": '2015信息简表',
            "author": 'czh'
        },{
            "name": '上海水泥厂',
            "location": '上海市',
            "title": '2015信息简表',
            "author": 'czh'
        }
        ]

export default class Ques_invite extends Component {
    state={
        current: 1,
        pagenum:5,
        data: [],
        visible: false,
    };

    componentDidMount = () => {
        this.setState({
            data : iniData
        })
    }
    handleOk = () =>{
        this.setState({
            visible: false
        })
    }
    handleCancel = () => {
        this.setState({
            visible: false
        })
    }
    deleteUser = (i) => {
        const data = this.state.data;
        data.splice(i,1);
        this.setState({
            data: data
        })
    }

    render() {
        const column = [
            {
                title: '公司名称',
                dataIndex: 'GSMC'
            },
            {
                title: '公司地址',
                dataIndex: 'GSDZ'
            },
            {
                title: '问卷名称',
                dataIndex: 'WJMC'
            },
            {
                title: '邀请人',
                dataIndex: 'YQR'
            },
            {
                title: '操作',
                dataIndex: 'CZ'
            }
        ]
        const datas = [];
        const dataItem = this.state.data;
        const len = dataItem.length;
        for(let i = 0; i< len; i++){
            datas.push({
                GSMC: dataItem[i].name,
                GSDZ: dataItem[i].location,
                WJMC: dataItem[i].title,
                YQR: dataItem[i].author,
                CZ: <span>
                {/* <Button type="primary" style = {{marginRight: '2px'}} onClick = {() => this.showModal(i)} >查看</Button> */}
                <Button type="primary" onClick = {() => this.deleteUser(i)} >删除</Button>
           </span>
            })
        }
        return (
            <div id="news_list">
                <div className="col-md-12 col-sm-12">
                    <h2>发放列表</h2>
                    <h3>您可以查看已发放问卷的工厂信息。</h3>
                    <Table columns = {column} dataSource = {datas} 
                        pagination = {{
                            showSizeChanger : true,
                            defaultCurrent : 1,
                            defaultPageSize: 4,
                            // total: len,
                            pageSizeOptions : ['4', '10', '30', '50'],//页数选择
                        }}
                    />
                    <Modal
                title="修改用户信息"
                visible={this.state.visible}
                onOk={this.handleOk}
                onCancel={this.handleCancel}
                >
                <div style = {{textAlign:'center'}} className = "modal">
                    <label  style = {{width:'100px',float:'left',textAlign:'right'}} >name:</label>
                    <p style = {{marginTop:'15px'}}><label style = {{width:'100px',float:'left',textAlign:'right'}} >email:</label></p>
                    <p><label style = {{width:'100px',float:'left',textAlign:'right'}} >status:</label></p>
                    <p><label style = {{width:'100px',float:'left',textAlign:'right'}} >location:</label></p>
                </div>
                </Modal>
                </div>
            </div>
        )
    }
}